package info.rongtong.action;

import java.util.HashMap;
import java.util.Map;

import info.rongtong.domain.Category;
import info.rongtong.service.inter.CategoryServiceInter;
import info.rongtong.utils.VariableUtils;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class AcategoryAction extends ActionSupport{
	private static final long serialVersionUID = -2315239137002666857L;
	private HttpServletRequest request = ServletActionContext.getRequest();
	private Category category;
	private Map<String, Object> map = new HashMap<String, Object>();
	private CategoryServiceInter categoryServiceImpl;
	
	/**
	 * 跳转到Ui页面
	 * @return
	 */
	public String goCategoryUi(){
		request.setAttribute("list", categoryServiceImpl.getAllCategory());
		return "categoryUi";
	}

	public String saveCategory(){
		categoryServiceImpl.saveOrUpdate(category);
		//更新变量，使线程得知类别已经添加
		VariableUtils.isUpdateCategory=true;
		map.put("result", "添加成功");
		return "addOk";
	}
	
	public void updateCategory(){
		categoryServiceImpl.saveOrUpdate(category);
		//更新变量，使线程得知类别已经添加
		VariableUtils.isUpdateCategory=true;
	}
	
	public void deleteCategory(){
		categoryServiceImpl.delObjectById(Category.class, category.getCid());
		//更新变量，使线程得知类别已经添加
		VariableUtils.isUpdateCategory=true;
	}
	
	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Map<String, Object> getMap() {
		return map;
	}

	public CategoryServiceInter getCategoryServiceImpl() {
		return categoryServiceImpl;
	}

	public void setCategoryServiceImpl(CategoryServiceInter categoryServiceImpl) {
		this.categoryServiceImpl = categoryServiceImpl;
	}
	
	
	
}
